<?php
namespace app\service;

class View
{

    use Instance;

    /**
     * renderPhpFile
     * @param string $file
     * @param array  $params
     * @return string
     */
    public function renderPhpFile(string $file, array $params = [])
    {
        $_obInitialLevel_ = ob_get_level();
        ob_start();
        ob_implicit_flush(false);
        extract($params, EXTR_OVERWRITE);
        try {
            require $file;
            return ob_get_clean();
        }catch (\Throwable $e) {
            while (ob_get_level() > $_obInitialLevel_) {
                if (!@ob_end_clean()) {
                    ob_clean();
                }
            }
            throw $e;
        }
    }
}